package org.bonorsoft.modules.wechat.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.bonorsoft.common.api.vo.Result;
import org.bonorsoft.common.system.base.controller.BonorController;
import org.bonorsoft.common.system.vo.LoginUser;
import org.bonorsoft.modules.wechat.entity.WxResponse;
import org.bonorsoft.modules.wechat.service.IWxResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * 呼应 回复信息
 */
@Slf4j
@Controller
@RequestMapping("/wechat/response")
public class WxResponseController extends BonorController<WxResponse, IWxResponseService> {

    @Autowired
    private IWxResponseService wxResponseService;


    /**
     * 呼应 回复 添加
     * @param wxResponse
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result<?> add(@RequestBody WxResponse wxResponse){
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();//取得当前用户
        String hfid = UUID.randomUUID().toString().replaceAll("-", "");
        wxResponse.setHfid(hfid).setHfsj(new Date()).setHfrid(user.getUsername()).setHfrxm(user.getRealname());
        wxResponseService.save(wxResponse);
        return Result.ok("添加成功！");
    }
}
